#include "bossplane.h"
#include"config.h"
#include<QDebug>

Bossplane::Bossplane()
{
    //加载boss机对象
    m_boss.load(BOSS_ENEMYPLANE);

    //boss机位置
    m_X=(GAME_WIDTH-m_boss.width())*0.5;
    m_Y=-m_boss.height(); ;

    //boss机状态
    m_boss_Free = true;

    //boss机速度
    m_speed = BOSS_SPEED;

    //boss机矩形边框
    m_Rect.setWidth(m_boss.width());
    m_Rect.setHeight(m_boss.height());
    m_Rect.moveTo(m_X,m_Y);

    //初始化boss机生命值
    m_hp = BOSS_HP;

    // 初始化子弹数组
    for (int i = 0; i < BULLET_NUM; i++) {
        m_boss_bullet[i].m_boss_Free = true;
    }


}

void Bossplane::shoot()
{
    //累加时间将记录变量
    m_recorder++;

    //如果记录的数字没有达到子弹发射的时间间隔，不发射子弹
    if(m_recorder<BULLET_INTERVAL*3)
    {
        return;
    }
    m_recorder = 0;
    for(int i = 0;i<BULLET_NUM;i++)
    {
        //如果子弹是空闲的，发射
        if(m_boss_bullet[i].m_boss_Free)
        {
        //将空闲状态改为假
        m_boss_bullet[i].m_boss_Free=false;

        //设置子弹坐标
        m_boss_bullet[i].m_boss_X=m_X+m_Rect.width()*0.5 - m_boss_bullet[i].m_boss_Bullet.width() * 0.5;
        m_boss_bullet[i].m_boss_Y=m_Y+m_Rect.height();
        break;
        }
    }
}

void Bossplane::updatePosition()
{
    //闲置机不更新状态
    if(m_boss_Free)
    {
        return;
    }

    //boss机向下移动
    if(m_Y<0)
    {
        m_Y+=BOSS_SPEED;
    }

    //boss机左右移动
    m_X += m_speed;
    if (m_X <= 0 || m_X >= GAME_WIDTH - m_Rect.width()) {
           m_speed = -m_speed;
       }
    m_Rect.moveTo(m_X,m_Y);
}
